I'm gonna overwrite a lot of this notebook's old content. I changed the way I'm calculating wt, and wanna test that my training worked.
In [1]:
from pearce.emulator import OriginalRecipe, ExtraCrispy, SpicyBuffalo
from pearce.mocks import cat_dict
import numpy as np
from os import path
In [2]:
import matplotlib
#matplotlib.use('Agg')
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
In [3]:
training_file = '/scratch/users/swmclau2/xi_zheng07_cosmo_lowmsat/PearceRedMagicXiCosmoFixedNd.hdf5'
test_file = '/scratch/users/swmclau2/xi_zheng07_cosmo_test//PearceRedMagicXiCosmoFixedNd_Test.hdf5'
em_method = 'gbdt'
#split_method = 'random'
In [4]:
a = 1.0
z = 1.0/a - 1.0
In [5]:
fixed_params = {'z':z}#, 'r':24.06822623}
In [6]:
#np.random.seed(0)
estimators = 100
emu = SpicyBuffalo(training_file, method = em_method, fixed_params=fixed_params,
custom_mean_function = 'linear', downsample_factor = 1.0,
hyperparams = {'n_estimators': estimators})#, 'max_depth': depth})
In [7]:
for i in xrange(50):
params = {}
for pname in emu.get_param_names():
if pname == 'r':
continue
low, high = emu.get_param_bounds(pname)
params[pname] = np.random.uniform(low, high)
pred_y = emu.emulate_wrt_r(params)[0]
plt.plot(emu.scale_bin_centers, pred_y)
plt.xscale('log')
plt.show()
#print pred_y
#print params
In [8]:
for i, (g, r) in enumerate(zip(gof, emu.scale_bin_centers)):
print r, g.mean(), np.median(g)
#plt.hist(np.log10(g))
#plt.show()
In [ ]:
n_cosmo_params = 7
loo_cosmo = emu.x[0, 0, :n_cosmo_params]
loo_cosmo_idxs = np.all(emu.x[:, :,:n_cosmo_params] == loo_cosmo, axis =2)
train_x, train_y, train_yerr = emu.x[~loo_cosmo_idxs, :], emu.y[ ~loo_cosmo_idxs], emu.yerr[ ~loo_cosmo_idxs]
test_x, test_y, test_yerr = emu.x[loo_cosmo_idxs, :], emu.y[loo_cosmo_idxs], emu.yerr[loo_cosmo_idxs]
In [ ]:
model = emu._emulator
model.compute(train_x, train_yerr)
In [ ]:
pred_y = model.predict(train_y, test_x, False, False, False)*emu._y_std + emu._y_mean
In [ ]:
np.mean(np.abs((pred_y-test_y)/test_y))
#np.mean(np.abs((pred_y-train_y)/train_y))
In [ ]:
queue_skipper: True
system: sherlock
n_jobs: 400
max_time: 6
resids = np.abs(emu.y*emu._y_std+emu._y_mean - ypred)
In [ ]:
np.mean(resids/(emu.y*emu._y_std+emu._y_mean))
In [ ]:
ypred.mean(), emu._y_mean
In [ ]:
test_gof = emu.goodness_of_fit(test_file, statistic = 'log_frac')
print test_gof.mean()
In [ ]:
test_gof = emu.goodness_of_fit(test_file, statistic = 'frac')
print test_gof.mean()
In [ ]:
plt.hist(np.log10(test_gof));
In [ ]:
test_x
In [ ]:
(emu.x*emu._x_std) + emu._x_mean
In [ ]:
emu.get_param_names()
In [ ]:
test_x_white, test_y_white = (test_x - emu._x_mean)/(emu._x_std + 1e-5), (test_y - emu._y_mean)/(emu._y_std + 1e-5)
In [ ]:
model = emu._emulator
In [ ]:
pred_y_white = model.predict(emu.y, test_x_white, False, False, False)
In [ ]:
pred_y = pred_y_white*emu._y_std + emu._y_mean
In [ ]:
plt.plot(pred_y[:100], label = 'pred')
plt.plot(test_y[:100], label = 'truth')
plt.legend(loc = 'best')
In [ ]:
test_y.mean(), emu._y_mean, pred_y.mean()
In [ ]:
test_y.std(), emu._y_std, pred_y.std()
In [ ]:
plt.hist(pred_y_white, bins = np.linspace(-3, 3, 100), label = 'Pred')
plt.hist(test_y_white, bins = np.linspace(-3, 3, 100), label = 'Test', alpha = 0.4);
plt.legend(loc = 'best')
In [ ]:
In [ ]: